Processing
Joystick Messages
The following
example illustrates how an application could respond to joystick movements and
changes in the button states. When the joystick changes position, the
application moves the cursor and, if either button is pressed, draws a bullet
hole on the desktop. When a joystick button is pressed, the application draws a
hole on the desktop and plays a sound continuously until a button is released.
The messages to watch are MM_JOY1MOVE, MM_JOY1BUTTONDOWN, and MM_JOY1BUTTONUPDUS5NW.
case MM_JOY1MOVE :                     // changed position 
    if((UINT)
wParam & (JOY_BUTTON1 | JOY_BUTTON2)) 
       
DrawFire(hWnd); 
   
DrawSight(lParam);                 // calculates new cursor position 
    break; 
case MM_JOY1BUTTONDOWN :               // button is down 
    if((UINT)
wParam & JOY_BUTTON1) 
    {  
       
PlaySound(lpButton1, SND_LOOP | SND_ASYNC | SND_MEMORY); 
       
DrawFire(hWnd); 
    } 
    else
if((UINT) wParam & JOY_BUTTON2) 
    {  
       
PlaySound(lpButton2, SND_ASYNC | SND_MEMORY |  SND_LOOP); 
       
DrawFire(hWnd); 
    } 
    break; 
case MM_JOY1BUTTONUP :                 // button is up 
   
sndPlaySound(NULL, 0);             // stops the sound 
    break;